home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 569 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  52 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: mgb@kronecker.mitre.org (G. Mike Butler D054)
  3. Newsgroups: comp.std.c++
  4. Subject: Semantics of "new foo[0]"
  5. Date: 27 Feb 1996 15:13:07 PST
  6. Organization: The MITRE Corporation
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <MGB.96Feb27175316@kronecker.mitre.org>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: 27 Feb 1996 22:53:16 GMT
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBVAwUBMTOQFUy4NqrwXLNJAQHyAQH/Uqi0qICJ0/QkIcQKIPns4ov7R83Hw+XV
  13.     eO/pcLOASDnwmB1VJmYtk17A0kOPKm2bJP0SK0zwhmTHfWST2KDbSg==
  14.     =a22R
  15. Originator: austern@isolde.mti.sgi.com
  16.  
  17. According to the ARM section 5.3.3:
  18.      "operator new() can be called with the argument
  19.       zero.  Repeated such calls return pointers to
  20.       distinct objects."  
  21.       
  22. But when I execute the following:
  23.     #include <isotream.h>
  24.     main()
  25.     {
  26.       struct foo { char a[1024]; };
  27.       foo *p = new foo[0];
  28.       foo *q = new foo[0];
  29.  
  30.       cout << (void *)p << " " << (void *)q << endl;
  31.     }
  32.  
  33. I get
  34.     0x338d8 0x338e8
  35.  
  36. While these are distinct pointers, the pointers refer to overlapping
  37. objects. Is this a legitimate interpretation of section 5.3.3 or is
  38. this a compiler/library bug?
  39.  
  40. Incidentally, the standard template library included with gcc 2.7.2
  41. relies on "operator new(0)" working.
  42.  
  43. Thanks,
  44. -Mike Butler
  45. ---
  46. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  47.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  48.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  49.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  50.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  51. ]
  52.